package com.ghost.view.login
{
	import com.ghost.model.Global_data;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;

	public class Global_pop_bg extends Sprite
	{
		public var bg_mc:DisplayObject;
		public var title_top_num:Number=5;//标题到bgtop的间距
		/**
		 * 自动生成背景 
		 * @param bg_width 9grid背景的宽度
		 * @param center top中间的图片
		 * @param title 标题图片
		 * @param sider_num 单边框的icon个数
		 * @param bg_point 9grid背景的初始坐标
		 * @param down_bg 下面图标和背景的下端坐标的差值
		 */
		public function Global_pop_bg(bg_width:Number,center:Bitmap=null,title:Bitmap=null,sider_num:int=20,bg_point:Point=null,down_bg:Number=-31)
		{
			var top_s:Sprite = new Sprite();
			this.addChild(top_s);
			if(bg_point==null)bg_point=new Point(32,46);
			var this_w:Number = bg_width;
			var pop_bg:* = Global_data.grid_ui_h.get("pop_bg");
			bg_mc = new pop_bg();
			this.addChild(bg_mc);
			bg_mc.x = bg_point.x;
			bg_mc.y = bg_point.y;
			bg_mc.width = bg_width-2*bg_point.x;
			
			var pop_sider_mc:Bitmap;
			var pop_sider:* = Global_data.grid_ui_h.get("pop_sider");
			for(var i:int=0;i<sider_num;i++)
			{
				for(var a:int = 0;a<2;a++)
				{
					pop_sider_mc = new pop_sider();
					pop_sider_mc.x = (a==0?bg_mc.x-pop_sider_mc.width/2:bg_mc.x+bg_mc.width-pop_sider_mc.width/2);
					pop_sider_mc.y = bg_mc.y+pop_sider_mc.height*i;
					this.addChild(pop_sider_mc);
					if(i==(sider_num-2)&&a==0)pop_sider_mc.name="end";
				}
			}
			bg_mc.height = this.getChildByName("end").y+this.getChildByName("end").height;
			
			var pop_top:* = Global_data.grid_ui_h.get("pop_top");
			var pop_top_left_mc:DisplayObject = new pop_top();
			pop_top_left_mc.width = this_w-pop_top_left_mc.width;
			var pop_top_right_mc:DisplayObject= new pop_top();
			pop_top_right_mc.scaleX=-1;
			pop_top_right_mc.x = pop_top_left_mc.width+pop_top_right_mc.width;
			this.addChild(pop_top_left_mc);
			this.addChild(pop_top_right_mc);
			
			var pop_down:* = Global_data.grid_ui_h.get("pop_down");
			var pop_down_left_mc:DisplayObject = new pop_down();
			pop_down_left_mc.width = this_w-pop_down_left_mc.width;
			var pop_down_right_mc:* = new pop_down();
			pop_down_right_mc.scaleX=-1;
			pop_down_right_mc.x = pop_down_left_mc.width+pop_down_right_mc.width;
			
			if(title)
			{
				this.addChild(title);
				title.x = bg_mc.width/2-title.width/2+bg_mc.x;
				title.y = bg_mc.y+title_top_num;
			}
			
			this.addChild(pop_down_left_mc);
			this.addChild(pop_down_right_mc);
			pop_down_left_mc.y = pop_down_right_mc.y = bg_mc.height+bg_mc.y+down_bg;
		}
	}
}